
//
//  JAddressListView.m
//  HeadIndustry
//
//  Created by jun on 2017/9/12.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JAddressListView.h"

@interface JAddressListView()

//@property (nonatomic , strong) 

@end

@implementation JAddressListView

- (instancetype)initWithFrame:(CGRect)frame addressmodel:(JAddressModel *)model
{
    if (self = [super initWithFrame:frame]) {
        _model = model;
        self.backgroundColor = [UIColor whiteColor];
        self.opaque = NO;
        [self setUpView];
    }
    return  self;
}

- (void)setUpView {
    UILabel *nameLa = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 40)];
    nameLa.text = _model.FirstName;
    nameLa.font = kFONT_TITLE(16);
    nameLa.textColor = kRGBColor(50, 50, 50);
    [self addSubview:nameLa];
    [nameLa sizeToFit];
    nameLa.frame = CGRectMake(15, 0, nameLa.width, 40);
    
    UILabel *telLa = [[UILabel alloc]initWithFrame:CGRectMake(nameLa.right + 10, 0, kWindowW - nameLa.right - 10 - 15, 40)];
    telLa.text = _model.PhoneNumber;
    telLa.font = kFONT_TITLE(16);
    telLa.textColor = kRGBColor(50, 50, 50);
    [self addSubview:telLa];
//    [telLa sizeToFit];
//    telLa.frame = CGRectMake(15, 0, nameLa.width, 40);
    
    UILabel *addLa = [[UILabel alloc]initWithFrame:CGRectMake(15, nameLa.bottom, kWindowW - 30, 40)];
    addLa.text = _model.FullAddress;
    addLa.font = kFONT_TITLE(16);
    addLa.numberOfLines = 0;
    addLa.textColor = kRGBColor(101, 101, 101);
    [self addSubview:addLa];
    [addLa sizeThatFits:CGSizeMake(kWindowW - 30, 100)];
    CGFloat height = 40;
    if (addLa.height > height) {
        height = addLa.height;
    }
    addLa.frame = CGRectMake(15, nameLa.bottom, kWindowW - 30, height);
    
    CALayer *line = [CALayer layer];
    line.backgroundColor = kRGBColor(150, 150, 150).CGColor;
    line.frame = CGRectMake(0, addLa.bottom - 0.5 , kWindowW, 0.5);
    [self.layer addSublayer:line];
    
    UIButton *setSelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    setSelBtn.frame = CGRectMake(0, addLa.bottom, 100, 40);
    setSelBtn.titleLabel.font = kFONT_TITLE(15);
    [setSelBtn setImage:[UIImage imageNamed:@"yuank"] forState:UIControlStateNormal];
    [setSelBtn setImage:[UIImage imageNamed:@"yesred"] forState:UIControlStateSelected];
    [setSelBtn setTitle:@" 设置默认" forState:UIControlStateNormal];
    [setSelBtn setTitleColor:kRGBColor(100, 100, 100) forState:UIControlStateNormal];
    [setSelBtn addTarget:self action:@selector(SetSelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    setSelBtn.tag = 1;
    [self addSubview:setSelBtn];
    _setDefaultbtn = setSelBtn;
    if (_model.IsDefaultAddress) {
        setSelBtn.selected = YES;
    }
    else
    {
        setSelBtn.selected = NO;
    }
    
    
    UIButton *delSelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    delSelBtn.frame = CGRectMake(kWindowW - 15 - 80, addLa.bottom, 80, 40);
    delSelBtn.titleLabel.font = kFONT_TITLE(15);
    [delSelBtn setImage:[UIImage imageNamed:@"del_icon"] forState:UIControlStateNormal];
    [delSelBtn setTitle:@" 删除" forState:UIControlStateNormal];
    [delSelBtn setTitleColor:kRGBColor(100, 100, 100) forState:UIControlStateNormal];

    [delSelBtn addTarget:self action:@selector(SetSelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    delSelBtn.tag = 3;

    [self addSubview:delSelBtn];
    
    
    UIButton *editSelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    editSelBtn.frame = CGRectMake(delSelBtn.left - 10 - 80, addLa.bottom, 80, 40);
    editSelBtn.titleLabel.font = kFONT_TITLE(15);
    [editSelBtn setImage:[UIImage imageNamed:@"edit_icon"] forState:UIControlStateNormal];
    [editSelBtn setTitle:@" 编辑" forState:UIControlStateNormal];
    [editSelBtn setTitleColor:kRGBColor(100, 100, 100) forState:UIControlStateNormal];

    [editSelBtn addTarget:self action:@selector(SetSelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    editSelBtn.tag = 2;

    [self addSubview:editSelBtn];
}

- (void)SetSelBtnClick:(UIButton *)btn
{
    
    if (_block) {
        _block(btn.tag,self.model);
    }
}

@end
